package com.zx.kitchen.index.common.http;

import android.app.ProgressDialog;
import android.content.Context;

import com.loopj.android.http.RequestParams;
import com.zx.kitchen.index.common.base.Contants;
import com.zx.kitchen.index.common.mvp.OnResultListener;
import com.zx.kitchen.index.common.utils.HttpUtils;
import com.zx.kitchen.index.common.utils.PreferenceUtil;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2017/3/3.
 */

public class HttpIndex {
    public static HttpIndex instanse;

    public static HttpIndex getInstanse() {
        if (instanse == null) {
            instanse = new HttpIndex();
        }
        return instanse;
    }

    public static void getLogin(Context context, String username, String password, OnResultListener listener, ProgressDialog progressDialog) {
        RequestParams params = new RequestParams();
        params.put("username", username);
        params.put("password", password);
        HttpUtils.post(context, Contants.LOGIN_URL, params, 1, listener, progressDialog);

    }

    public static void getIndexOrderCommit(Context context, String ids, String cache_data,
                                           boolean type, OnResultListener listener, ProgressDialog progressDialog) {
        RequestParams params = new RequestParams();
        params.put("user_data", PreferenceUtil.getStringData(context, Contants.spToken));
        params.put("ids", ids);
        params.put("cache_data", cache_data);//可以为空
        if (type) {
            HttpUtils.post(context, Contants.PURCHASE_PRICENUM_URL, params, 1, listener, progressDialog);
        } else {
            HttpUtils.post(context, Contants.INDEX_PRICENUM_URL, params, 1, listener, progressDialog);
        }
    }


    //创建订单
    public static void getOrderCreate(Context context, String customer_name, String receive_money,
                                      String[] id, String[] num, String[] price,boolean type,
                                      OnResultListener listener, ProgressDialog progressDialog) {
        RequestParams params = new RequestParams();
        params.put("user_data", PreferenceUtil.getStringData(context, Contants.spToken));
        params.put("customer_name", customer_name);
        params.put("receive_money", receive_money);
        params.put("id", id);
        params.put("num", num);
        params.put("price", price);
        if (type){
            HttpUtils.post(context, Contants.PURCHASE_CREATE_ORDER_URL, params, 1, listener, progressDialog);
        }else {
            HttpUtils.post(context, Contants.INDEX_CREATE_ORDER_URL, params, 1, listener, progressDialog);
        }

    }

    public static void saveBusinessInfo(Context context, String logo, String qr_code, String name, String companytel, String mobile, String companyaddress,
                                        int day_hour, int month_day, String activity, int activity_print,
                                        OnResultListener listener, ProgressDialog progressDialog) {


//        RequestParams params = new RequestParams();
//        params.put("user_data", PreferenceUtil.getStringData(context, Contants.spToken));
//        params.put("name", name);
//        params.put("companytel", companytel);
//        params.put("companyaddress", companyaddress);
//        params.put("mobile", mobile);
//        params.put("activity", activity);
//        params.put("day_hour", day_hour);
//        params.put("month_day", month_day);
//        params.put("activity_print", activity_print);
//        HttpUtils.post(context, Contants.COMPANY_SAVE_URL, params, 1, listener, progressDialog);


        Map<String, String> map = new HashMap<>();
        Map<String, Integer> map2 = new HashMap<>();
        map.put("user_data", PreferenceUtil.getStringData(context, Contants.spToken));
        map.put("name", name);
        map.put("companytel", companytel);
        map.put("companyaddress", companyaddress);
        map.put("mobile", mobile);
        map.put("activity", activity);
        map2.put("day_hour", day_hour);
        map2.put("month_day", month_day);
        map2.put("activity_print", activity_print);
        try {
            HttpUtils.uploadFileAll(context, "logo", logo, "qr_code", qr_code, Contants.COMPANY_SAVE_URL, map, map2, listener, progressDialog);
        } catch (Exception e) {
            e.printStackTrace();
        }

//        HttpUtils.uploadFile(logo,Contants.COMPANY_SAVE_URL,context);

    }

    public static void getBusinessInfo(Context context, OnResultListener listener, ProgressDialog progressDialog) {
        RequestParams params = new RequestParams();
        params.put("user_data", PreferenceUtil.getStringData(context, Contants.spToken));
        HttpUtils.post(context, Contants.COMPANY_INDEX_URL, params, 1, listener, progressDialog);

    }

}
